
$(function(){
	//接收参数
	showCondition(false);
	//加载病例
	loadCase();
});
/**
 * 
 * @ Discription:加载病例明细
 * @Autor ：liuhongjun
 * @param caseLinkCode
 * @returns
 * any
 * case.js
 * 2017年6月18日下午6:53:17
 */
function loadCase() {
	$('#'+tabId+' #content').html('<table class="table display nowrap" style="width:100%;"  id="caseTableForDelete"'
		 		+'style="text-align: center;">'
		 		+'</table>');
	loadPageData();
}
function loadPageData(filterStr){
	$('#'+tabId+' #loading').fadeIn(0);
	var colunms=[ 
	             { 
	 				"data": "MR_NO",title:"病案号",
	 				"render": function(obj, type, full){
	 					var mrNo = full.MR_NO;
	 					return "<a href=\"javascript:medicalRecord('"+full.PMAININDEX+"','"+full.PATIENT_NAME+"')\">"+mrNo+"</a>";
	 				}
	             },
	             { "data": "PMAININDEX",title:"健康卡号"},
	             { "data": "PATIENT_NAME",title:"姓名" },
	             { 
	           	  "data": "SEX",title:"性别",
	           	  "render": function(obj, type, full) {
	           		  var a='1';
	 		               var sex=$.trim(full.SEX);
	 		               if(sex == "1"){
	 		              	 sex = "男";
	 		               }else if(sex == "2"){
	 		              	 sex = "女";
	 		               }else{
	 		              	 sex = "未知";
	 		               }
	 		               return sex;
	           	  }
	             },
	             { 
	           	  "data": "AGE_YEAR" ,title:"年龄",
	           	  "render": function(obj, type, full) {
	           		  if(full.AGE_YEAR>0){
	           			  return full.AGE_YEAR;
	           		  } else if(full.AGE_MONTH>0 && full.AGE_DAYS>0){
	           			return full.AGE_MONTH + '月' + full.AGE_DAYS + '天';
	           		  } else if(full.AGE_MONTH>0){
	           			  return full.AGE_MONTH + '月';
	           		  } else if(full.AGE_DAYS>0){
	           			  return full.AGE_DAYS + '天';
	           		  } 
	           	  }
	             },
	             { "data": "IN_DATE",title:"入院时间"},
	             { "data": "OUT_DATE",title:"出院时间",
	           	   "render": function(obj, type, full) {
	           		  return full.OUT_DATE;
	           	   }
	             },
	             { "data": "DEP_NAME",title:"出院科室" },
	             { "data": "IN_DAYS",title:"住院日" },
	             { "data": "COSTAMOUNT",title:"总费用(元)", "type":"numeric-comma",
	 				 "render": function(obj, type, full) {
	 					return formatNumber(full.COSTAMOUNT);
	 				 }
	 			 },
	             { "data": "DRUG_COST" ,title:"药品费用(元)", "type":"numeric-comma",
	 				 "render": function(obj, type, full) {
	 						return formatNumber(full.DRUG_COST);
	 					 }
	             },
	             { "data": "DIAGNOSE_DESC_MAIN",title:"主要诊断",
	            	 "render": function(obj, type, full) {
	            		 return linefeedText(obj);
	            	 }
                 },
                 { "data": "OPERATION",title:"操作",
	            	 "render": function(obj, type, full) {
	            		 return "<a href='javascript: deleteCaseData(\""+full.PMAININDEX+"\")'>删除</a>";
	            	 }
                 },
	             ];
	var paramFilterStr = " and 1>2 ";
	if(filterStr){
		paramFilterStr = " AND (INSTR(BASE.P00060000, '"+filterStr+"')>0 OR INSTR(BASE.PMAININDEX, '"+filterStr+"')>0 OR INSTR(BASE.P00050000, '"+filterStr+"')>0 OR INSTR(IP.P00300000, '"+filterStr+"')>0 AND INSTR(TO_CHAR(IP.P00290000, 'YYYY-MM-DD'), '"+filterStr+"')>0) ";
	}
 	 $.ajax({
             "dataType": 'json', 
             "type": "POST", 
             "url": contextPath + "/DrgsIndexCal/findCaseListGlobal.dhc",
             "data": {
            	"filterStr": paramFilterStr,  
             },
             "success": function(result) {
				var paramsDataTables={tableTitle:'病例明细表',scrollX:true,scrollY:'350px',autoWidth:false,orderCellsTop:true,pageLength:50,lengthMenu:[[ 50,100,500, 1000,99999],[ 50,100,500, 1000,'全部']]};
				var oTable=$('#'+tabId+' #caseTableForDelete').dataTableBasic(colunms, result.data, paramsDataTables);
				if(filterStr){
					$("#"+tabId+" #caseTableForDelete_filter").html("<label>搜索 <input type='text' id='caseTableForDelete_filter_value' title='病案号、姓名、出院科室、出院时间' placeholder='病案号、姓名、出院科室、出院时间'  value='"+filterStr+"'></label>")
				}else{
					$("#"+tabId+" #caseTableForDelete_filter").html("<label>搜索 <input type='text' id='caseTableForDelete_filter_value' title='病案号、姓名、出院科室、出院时间' placeholder='病案号、姓名、出院科室、出院时间'></label>")
				}
				$('#'+tabId+' #loading').fadeOut(0);
				//重写过滤方法
				$("#"+tabId+" #caseTableForDelete_filter_value").keydown(function(e){
					if(e.keyCode==13){
						var filterStr = $("#"+tabId+" #caseTableForDelete_filter_value").val();
						loadPageData(filterStr);
					}
				});
			}
    });
}

function deleteCaseData(parid){
	$(this).confirm({
        content : '确定要删除病例'+parid+"吗? 删除后将无法恢复!",
        callBack : function() {
            $.post(contextPath+"/DrgsIndexCal/deleteCase.dhc", {parid: parid}, function(data){
                if(data.success){
                	drgUI.success("删除成功！")
                    var filterStr = $("#"+tabId+" #caseTableForDelete_filter_value").val();
					loadPageData(filterStr);
                }else{
                	drgUI.success("删除失败！"+data.errorMessage);
                }
            });
        }
    });
}

